<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="Hexo Theme Keep">
    <meta name="description" content="Hexo Theme Keep">
    <meta name="author" content="Da">
    
    <title>
        
            servler学习笔记 |
        
        Da的个人博客
    </title>
    
<link rel="stylesheet" href="/css/style.css">

    <link rel="shortcut icon" href="/images/logo.svg">
    
<link rel="stylesheet" href="/css/font-awesome.min.css">

    <script id="hexo-configurations">
    let KEEP = window.KEEP || {};
    KEEP.hexo_config = {"hostname":"da9527.gitee.io","root":"/","language":"zh-CN","path":"search.json"};
    KEEP.theme_config = {"toc":{"enable":true,"number":false,"expand_all":false,"init_open":false},"style":{"primary_color":"#CC0000","avatar":"/images/avatar.svg","favicon":"/images/logo.svg","article_img_align":"left","left_side_width":"260px","content_max_width":"920px","hover":{"shadow":true,"scale":true},"first_screen":{"enable":true,"background_img":"/images/bg.svg","description":"我不怕千万人阻挡,只怕自己投降"},"scroll":{"progress_bar":{"enable":false},"percent":{"enable":false}}},"local_search":{"enable":true,"preload":false},"code_copy":{"enable":true,"style":"default"},"pjax":{"enable":true},"lazyload":{"enable":true},"version":"3.4.2"};
    KEEP.language_ago = {"second":"%s 秒前","minute":"%s 分钟前","hour":"%s 小时前","day":"%s 天前","week":"%s 周前","month":"%s 月前","year":"%s 年前"};
  </script>
<meta name="generator" content="Hexo 5.4.0"></head>


<body>
<div class="progress-bar-container">
    

    
        <span class="pjax-progress-bar"></span>
        <span class="pjax-progress-icon">
            <i class="fas fa-circle-notch fa-spin"></i>
        </span>
    
</div>


<main class="page-container">

    

    <div class="page-main-content">

        <div class="page-main-content-top">
            <header class="header-wrapper">

    <div class="header-content">
        <div class="left">
            <a class="logo-title" href="/">
                Da的个人博客
            </a>
        </div>

        <div class="right">
            <div class="pc">
                <ul class="menu-list">
                    
                        <li class="menu-item">
                            <a class=""
                               href="/"
                            >
                                首页
                            </a>
                        </li>
                    
                        <li class="menu-item">
                            <a class=""
                               href="/archives"
                            >
                                归档
                            </a>
                        </li>
                    
                        <li class="menu-item">
                            <a class=""
                               href="/about"
                            >
                                关于
                            </a>
                        </li>
                    
                    
                        <li class="menu-item search search-popup-trigger">
                            <i class="fas fa-search"></i>
                        </li>
                    
                </ul>
            </div>
            <div class="mobile">
                
                    <div class="icon-item search search-popup-trigger"><i class="fas fa-search"></i></div>
                
                <div class="icon-item menu-bar">
                    <div class="menu-bar-middle"></div>
                </div>
            </div>
        </div>
    </div>

    <div class="header-drawer">
        <ul class="drawer-menu-list">
            
                <li class="drawer-menu-item flex-center">
                    <a class=""
                       href="/">首页</a>
                </li>
            
                <li class="drawer-menu-item flex-center">
                    <a class=""
                       href="/archives">归档</a>
                </li>
            
                <li class="drawer-menu-item flex-center">
                    <a class=""
                       href="/about">关于</a>
                </li>
            
        </ul>
    </div>

    <div class="window-mask"></div>

</header>


        </div>

        <div class="page-main-content-middle">

            <div class="main-content">

                
                    <div class="fade-in-down-animation">
    <div class="article-content-container">

        <div class="article-title">
            <span class="title-hover-animation">servler学习笔记</span>
        </div>

        
            <div class="article-header">
                <div class="avatar">
                    <img src="/images/avatar.svg">
                </div>
                <div class="info">
                    <div class="author">
                        <span class="name">Da</span>
                        
                            <span class="author-label">Lv4</span>
                        
                    </div>
                    <div class="meta-info">
                        <div class="article-meta-info">
    <span class="article-date article-meta-item">
        <i class="fas fa-edit"></i>&nbsp;2021-05-01 09:56:05
    </span>
    
    

    
    
        <span class="article-wordcount article-meta-item">
            <i class="fas fa-file-word"></i>&nbsp;<span>227 字</span>
        </span>
    
    
        <span class="article-min2read article-meta-item">
            <i class="fas fa-clock"></i>&nbsp;<span>1 分钟</span>
        </span>
    
    
        <span class="article-pv article-meta-item">
            <i class="fas fa-eye"></i>&nbsp;<span id="busuanzi_value_page_pv"></span>
        </span>
    
</div>

                    </div>
                </div>
            </div>
        

        <div class="article-content markdown-body">
            <h1 id="Servlet-简介"><a href="#Servlet-简介" class="headerlink" title="Servlet 简介"></a>Servlet 简介</h1><h3 id="Servlet-是什么？"><a href="#Servlet-是什么？" class="headerlink" title="Servlet 是什么？"></a>Servlet 是什么？</h3><p>Java Servlet 是运行在 Web 服务器或应用服务器上的程序，它是作为来自 Web 浏览器或其他 HTTP 客户端的请求和 HTTP 服务器上的数据库或应用程序之间的中间层。</p>
<p>使用 Servlet，您可以收集来自网页表单的用户输入，呈现来自数据库或者其他源的记录，还可以动态创建网页。</p>
<h3 id="1、Hello-Servlet"><a href="#1、Hello-Servlet" class="headerlink" title="1、Hello Servlet"></a>1、Hello Servlet</h3><h3 id="新建javaWeb工程-如图所示-视频教程"><a href="#新建javaWeb工程-如图所示-视频教程" class="headerlink" title="新建javaWeb工程(如图所示)视频教程"></a>新建javaWeb工程(如图所示)<a class="link"   target="_blank" rel="noopener" href="https://www.bilibili.com/video/bv1by4y1s7Mo" >视频教程<i class="fas fa-external-link-alt"></i></a></h3><h4 id="1、新建java工程"><a href="#1、新建java工程" class="headerlink" title="1、新建java工程"></a>1、新建java工程</h4><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="https://i.loli.net/2021/05/01/RPM4nDEqH5zchvt.png"
                      alt="image.png" style="zoom:50%;" /
                >

<h4 id="下一步"><a href="#下一步" class="headerlink" title="下一步"></a>下一步</h4><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="https://i.loli.net/2021/05/01/563Th7gQpviKaRo.png"
                      alt="image.png" style="zoom:50%;" /
                >

<h4 id="起个名字"><a href="#起个名字" class="headerlink" title="起个名字"></a>起个名字</h4><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="https://i.loli.net/2021/05/01/OVMe46LJ7uaglhf.png"
                      alt="image.png" style="zoom:50%;" /
                >

<h4 id="改成web工程"><a href="#改成web工程" class="headerlink" title="改成web工程"></a>改成web工程</h4><p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="https://i.loli.net/2021/05/01/ertCEzpT4JyBo6M.png"
                      alt="image.png"
                ></p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="https://i.loli.net/2021/05/01/W7xhzFDBuqHa6AY.png"
                      alt="image.png"
                ></p>
<h4 id="添加tomcat目录下的lib依赖"><a href="#添加tomcat目录下的lib依赖" class="headerlink" title="添加tomcat目录下的lib依赖"></a>添加tomcat目录下的lib依赖</h4><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="https://i.loli.net/2021/05/01/D5KMQpnaRgo9w1u.png"
                      alt="image.png" style="zoom:50%;" /
                >

<img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="https://i.loli.net/2021/05/01/FuNVPfHvCQ3Xsyd.png"
                      alt="image.png" style="zoom:50%;" /
                >

<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="https://i.loli.net/2021/05/01/5Fj94ztlmp3SPao.png"
                      alt="image.png"
                ></p>
<img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="https://i.loli.net/2021/05/01/jqgLNx9DszcEV5K.png"
                      alt="image.png" style="zoom:50%;" /
                >

<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="https://i.loli.net/2021/05/01/DEa9n6LUmqioywB.png"
                      alt="image.png"
                ></p>
<img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="https://i.loli.net/2021/05/01/4S2xHUXMmgqvWeh.png"
                      alt="image.png" style="zoom:50%;" /
                >

<h4 id="有tomcat的依赖就行"><a href="#有tomcat的依赖就行" class="headerlink" title="有tomcat的依赖就行"></a>有tomcat的依赖就行</h4><p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="https://i.loli.net/2021/05/01/pR3wATScrsnuQ7U.png"
                      alt="image.png"
                ></p>
<h4 id="在web工程的src下新建包，在包里新建一个HelloServlet类"><a href="#在web工程的src下新建包，在包里新建一个HelloServlet类" class="headerlink" title="在web工程的src下新建包，在包里新建一个HelloServlet类:"></a>在web工程的src下新建包，在包里新建一个HelloServlet类:</h4><p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="https://i.loli.net/2021/05/01/xQmTVXsoJRbGFwI.png"
                      alt="image.png"
                ></p>
<img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="https://i.loli.net/2021/05/01/yKPzawFvMmID5d2.png"
                      alt="image.png" style="zoom:50%;" /
                >

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 第一个servlet程序HelloServlet</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@WebServlet(&quot;/hello&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloServlet</span> <span class="keyword">extends</span> <span class="title">HttpServlet</span> </span>&#123;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title">service</span><span class="params">(HttpServletRequest req, HttpServletResponse resp)</span> <span class="keyword">throws</span> ServletException, IOException </span>&#123;</span><br><span class="line">        resp.getWriter().write(<span class="string">&quot;HelloServlet&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="运行环境配置："><a href="#运行环境配置：" class="headerlink" title="运行环境配置："></a>运行环境配置：</h3><p>​    <img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="https://i.loli.net/2021/05/01/Pj4Zsnc5dliVkwH.png"
                      alt="image.png"
                ></p>
<img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="https://i.loli.net/2021/05/01/ojWp58kXf9FRgmN.png"
                      alt="image.png" style="zoom:50%;" /
                >

<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="https://i.loli.net/2021/05/01/WLfPX9aiOyoUDqm.png"
                      alt="image.png"
                ></p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="https://i.loli.net/2021/05/01/3aRYLK129FHBqWI.png"
                      alt="image.png"
                ></p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="https://static01.imgkr.com/temp/c3114f06e81141b981d6bcd49c0993a1.png"
                      alt="image.png"
                ></p>
<h4 id="运行"><a href="#运行" class="headerlink" title="运行"></a>运行</h4><p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="https://static01.imgkr.com/temp/cbbef4c6c06644818d572f42d4da4249.png"
                      alt="image.png"
                ></p>
<h4 id="运行结果"><a href="#运行结果" class="headerlink" title="运行结果:"></a>运行结果:</h4><p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="https://i.loli.net/2021/05/01/KAWfhP1TsIaB2oO.png"
                      alt="image.png"
                ></p>

        </div>

        
            <div class="post-copyright-info">
                <div class="article-copyright-info-container">
    <ul>
        <li>本文标题：servler学习笔记</li>
        <li>本文作者：Da</li>
        <li>创建时间：2021-05-01 09:56:05</li>
        <li>
            本文链接：https://da9527.gitee.io/2021/05/01/servler学习笔记/
        </li>
        <li>
            版权声明：本博客所有文章除特别声明外，均采用 <a class="license" target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">BY-NC-SA</a> 许可协议。转载请注明出处！
        </li>
    </ul>
</div>

            </div>
        

        
            <div class="article-nav">
                
                    <div class="article-prev">
                        <a class="prev"
                           rel="prev"
                           href="/2021/05/13/Jdk%E5%8A%A8%E6%80%81%E4%BB%A3%E7%90%86/"
                        >
                            <span class="left arrow-icon flex-center">
                              <i class="fas fa-chevron-left"></i>
                            </span>
                            <span class="title flex-center">
                                <span class="post-nav-title-item">Jdk动态代理</span>
                                <span class="post-nav-item">上一篇</span>
                            </span>
                        </a>
                    </div>
                
                
                    <div class="article-next">
                        <a class="next"
                           rel="next"
                           href="/2021/04/24/markdown%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/"
                        >
                            <span class="title flex-center">
                                <span class="post-nav-title-item">markdown学习笔记</span>
                                <span class="post-nav-item">下一篇</span>
                            </span>
                            <span class="right arrow-icon flex-center">
                              <i class="fas fa-chevron-right"></i>
                            </span>
                        </a>
                    </div>
                
            </div>
        

        
    </div>
</div>


                
            </div>

        </div>

        <div class="page-main-content-bottom">
            <footer class="footer">
    <div class="info-container">
        <div class="copyright-info info-item">
            &copy;
            
              <span>2020</span>&nbsp;-&nbsp;
            
            2021&nbsp;<i class="fas fa-heart icon-animate"></i>&nbsp;<a href="/">Da</a>
        </div>
        
            <script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
            <div class="website-count info-item">
                
                    <span id="busuanzi_container_site_uv">
                        访问人数&nbsp;<span id="busuanzi_value_site_uv"></span>&ensp;
                    </span>
                
                
                    <span id="busuanzi_container_site_pv">
                        总访问量&nbsp;<span id="busuanzi_value_site_pv"></span>
                    </span>
                
            </div>
        
        <div class="theme-info info-item">
            由 <a target="_blank" href="https://hexo.io">Hexo</a> 驱动&nbsp;|&nbsp;主题&nbsp;<a class="theme-version" target="_blank" href="https://github.com/XPoet/hexo-theme-keep">Keep v3.4.2</a>
        </div>
        
    </div>
</footer>

        </div>
    </div>

    
        <div class="post-tools">
            <div class="post-tools-container">
    <ul class="tools-list">
        <!-- TOC aside toggle -->
        
            <li class="tools-item page-aside-toggle">
                <i class="fas fa-outdent"></i>
            </li>
        

        <!-- go comment -->
        
    </ul>
</div>

        </div>
    

    <div class="right-bottom-side-tools">
        <div class="side-tools-container">
    <ul class="side-tools-list">
        <li class="tools-item tool-font-adjust-plus flex-center">
            <i class="fas fa-search-plus"></i>
        </li>

        <li class="tools-item tool-font-adjust-minus flex-center">
            <i class="fas fa-search-minus"></i>
        </li>

        <li class="tools-item tool-expand-width flex-center">
            <i class="fas fa-arrows-alt-h"></i>
        </li>

        <li class="tools-item tool-dark-light-toggle flex-center">
            <i class="fas fa-moon"></i>
        </li>

        <!-- rss -->
        

        
            <li class="tools-item tool-scroll-to-top flex-center">
                <i class="fas fa-arrow-up"></i>
            </li>
        

        <li class="tools-item tool-scroll-to-bottom flex-center">
            <i class="fas fa-arrow-down"></i>
        </li>
    </ul>

    <ul class="exposed-tools-list">
        <li class="tools-item tool-toggle-show flex-center">
            <i class="fas fa-cog fa-spin"></i>
        </li>
        
    </ul>
</div>

    </div>

    
        <aside class="page-aside">
            <div class="post-toc-wrap">
    <div class="post-toc">
        <ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Servlet-%E7%AE%80%E4%BB%8B"><span class="nav-text">Servlet 简介</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Servlet-%E6%98%AF%E4%BB%80%E4%B9%88%EF%BC%9F"><span class="nav-text">Servlet 是什么？</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1%E3%80%81Hello-Servlet"><span class="nav-text">1、Hello Servlet</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%96%B0%E5%BB%BAjavaWeb%E5%B7%A5%E7%A8%8B-%E5%A6%82%E5%9B%BE%E6%89%80%E7%A4%BA-%E8%A7%86%E9%A2%91%E6%95%99%E7%A8%8B"><span class="nav-text">新建javaWeb工程(如图所示)视频教程</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1%E3%80%81%E6%96%B0%E5%BB%BAjava%E5%B7%A5%E7%A8%8B"><span class="nav-text">1、新建java工程</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E4%B8%8B%E4%B8%80%E6%AD%A5"><span class="nav-text">下一步</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%B5%B7%E4%B8%AA%E5%90%8D%E5%AD%97"><span class="nav-text">起个名字</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%94%B9%E6%88%90web%E5%B7%A5%E7%A8%8B"><span class="nav-text">改成web工程</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%B7%BB%E5%8A%A0tomcat%E7%9B%AE%E5%BD%95%E4%B8%8B%E7%9A%84lib%E4%BE%9D%E8%B5%96"><span class="nav-text">添加tomcat目录下的lib依赖</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%9C%89tomcat%E7%9A%84%E4%BE%9D%E8%B5%96%E5%B0%B1%E8%A1%8C"><span class="nav-text">有tomcat的依赖就行</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%9C%A8web%E5%B7%A5%E7%A8%8B%E7%9A%84src%E4%B8%8B%E6%96%B0%E5%BB%BA%E5%8C%85%EF%BC%8C%E5%9C%A8%E5%8C%85%E9%87%8C%E6%96%B0%E5%BB%BA%E4%B8%80%E4%B8%AAHelloServlet%E7%B1%BB"><span class="nav-text">在web工程的src下新建包，在包里新建一个HelloServlet类:</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%BF%90%E8%A1%8C%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE%EF%BC%9A"><span class="nav-text">运行环境配置：</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%BF%90%E8%A1%8C"><span class="nav-text">运行</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%BF%90%E8%A1%8C%E7%BB%93%E6%9E%9C"><span class="nav-text">运行结果:</span></a></li></ol></li></ol></li></ol></li></ol>
    </div>
</div>
        </aside>
    

    <div class="image-viewer-container">
    <img src="">
</div>


    
        <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
          <span class="search-input-field-pre">
            <i class="fas fa-keyboard"></i>
          </span>
            <div class="search-input-container">
                <input autocomplete="off"
                       autocorrect="off"
                       autocapitalize="off"
                       placeholder="搜索..."
                       spellcheck="false"
                       type="search"
                       class="search-input"
                >
            </div>
            <span class="popup-btn-close">
                <i class="fas fa-times"></i>
            </span>
        </div>
        <div id="search-result">
            <div id="no-result">
                <i class="fas fa-spinner fa-pulse fa-5x fa-fw"></i>
            </div>
        </div>
    </div>
</div>

    

</main>




<script src="/js/utils.js"></script>

<script src="/js/main.js"></script>

<script src="/js/header-shrink.js"></script>

<script src="/js/back2top.js"></script>

<script src="/js/dark-light-toggle.js"></script>



    
<script src="/js/local-search.js"></script>




    
<script src="/js/code-copy.js"></script>




    
<script src="/js/lazyload.js"></script>



<div class="post-scripts pjax">
    
        
<script src="/js/left-side-toggle.js"></script>

<script src="/js/libs/anime.min.js"></script>

<script src="/js/toc.js"></script>

    
</div>


    
<script src="/js/libs/pjax.min.js"></script>

<script>
    window.addEventListener('DOMContentLoaded', () => {
        const pjax = new Pjax({
            selectors: [
                'head title',
                '.page-container',
                '.pjax'
            ],
            history: true,
            debug: false,
            cacheBust: false,
            timeout: 0,
            analytics: false,
            currentUrlFullReload: false,
            scrollRestoration: false,
            // scrollTo: true,
        });

        document.addEventListener('pjax:send', () => {
            KEEP.utils.pjaxProgressBarStart();
        });

        document.addEventListener('pjax:complete', () => {
            KEEP.utils.pjaxProgressBarEnd();
            pjax.executeScripts(document.querySelectorAll('script[data-pjax], .pjax script'));
            KEEP.refresh();
        });
    });
</script>



<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/shizuku.model.json"},"display":{"position":"left","width":120,"height":240},"mobile":{"show":false},"log":false});</script></body>
</html>
